const client = require('../utils/redis');
class GeoCtl {
    async add(ctx) {
        const key = ctx.request.body.key
        const val1 = ctx.request.body.val1
        const val2 = ctx.request.body.val2
        const val3 = ctx.request.body.val3
        const redisData = await new Promise((resolve, reject) => {
            client.select('1', function (err) {
                if (err) {
                    return resolve({code: -1})
                } else {
                    client.geoadd(key,val1,val2,val3, function (err, res) {
                        if (err) {
                            console.log(err)
                            return resolve({code: -1})
                        } else {
                            return resolve({code: 200, data: res})
                        }
                    })
                }
            })
        });
        if (redisData.code === 200) {
            ctx.body={code:200,msg:"OK"}
        } else {
            ctx.body = {code: -1}
        }

    }

}

module.exports = new GeoCtl ();